package com.hgk.wanwan.regist;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.common.android.volley.VolleyError;
import com.hgk.common.common.constants.DataConstants;
import com.hgk.common.common.ui.activity.SimpleBaseActivity;
import com.hgk.common.common.ui.view.RippleView;

import java.util.Map;

import width.hgk.wanwan.R;

public class PsdActivity extends SimpleBaseActivity {

    private String mPhoneNum,mCode,mPsdWord;
    private EditText mEtPsd;
    private LinearLayout mLltPsd;
    private ImageView mIvDelete ,mIvSee;
    private RippleView mRipRegist;
    private String type = "0";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView();
        mPhoneNum = getIntent().getStringExtra(DataConstants.TEL_NUMBER);
        mCode = getIntent().getStringExtra(DataConstants.TEL_CODE);
        initView();
    }

    private void initView() {
        mLltPsd = (LinearLayout) findViewById(R.id.llt_psd_edit);
        mEtPsd = (EditText) findViewById(R.id.et_psd_edit);
        mIvDelete = (ImageView) findViewById(R.id.iv_psd_delete);
        mRipRegist = (RippleView) findViewById(R.id.rip_psd_btn);
        mIvSee = (ImageView) findViewById(R.id.iv_psd_see);

        if (!TextUtils.isEmpty(mEtPsd.getText().toString())){
            mIvSee.setVisibility(View.VISIBLE);
        }else{
            mIvSee.setVisibility(View.GONE);
        }
        mIvSee.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (type.equals("0")){
                    type="1";
                    mEtPsd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                }else{
                    type = "0";
                    mEtPsd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
            }
        });

        mRipRegist.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                if (!TextUtils.isEmpty(mEtPsd.getText().toString())){
                    mPsdWord = mEtPsd.getText().toString();
                }
            }
        });
    }

    @Override
    protected Map getApiParams(String action) {
        return null;
    }

    @Override
    protected void success(String action, Object result) {

    }

    @Override
    protected void fail(String action, String errorStr) {

    }

    @Override
    protected void netfail(String action, VolleyError volleyError) {

    }

    @Override
    public void setLeftButton(RelativeLayout relativeLayout, Button button) {

    }

    @Override
    public void setRightButton(RelativeLayout relativeLayout, Button button) {

    }

    @Override
    public Object getTitleString() {
        return "注册";
    }

    @Override
    public int getBodyView() {
        return R.layout.activity_psd;
    }

    public static void launch(Context context,String phoneNumber,String code){
        Intent intent = new Intent(context,PsdActivity.class);
        intent.putExtra(DataConstants.TEL_NUMBER,phoneNumber);
        intent.putExtra(DataConstants.TEL_CODE,code);
        context.startActivity(intent);
    }
}
